<script setup lang="ts">
import blog_table, {type optionType} from '@/components/admin/blog_table.vue';
import {userDelAxios, userListAxios} from "@/api/user_api";
import {Message} from '@arco-design/web-vue';
import {getCurrentInstance, ref} from 'vue';
import User_add_modal from "@/views/admin/user/user_add_modal.vue";
import User_update_modal from "@/views/admin/user/user_update_modal.vue";

const columns = [
  {title: '昵称', dataIndex: 'nick_name',},
  {title: '用户名', dataIndex: 'user_name',},
  {title: '头像', slotName: 'avatar',},
  {title: '邮箱', dataIndex: 'email',},
  {title: '角色', dataIndex: 'role',},
  {title: 'ip', dataIndex: 'ip',},
  {title: '注册时间', slotName: 'created_at',},
  {title: '操作', slotName: 'action',},
]
const actionOptionList = ref<optionType[]>([
  {label: "批量删除", value: 1},
])
const filterOptionList = ref<optionType[]>([
  {
    label: "角色过滤",
    value: 1,
    column: "role",
    options: [{label: "管理员", value: 1}, {label: "普通登录人", value: 2}]
  },
  {
    label: "ip过滤",
    value: 2,
    column: "ip",
    options: [{label: "北京", value: 1}, {label: "上海", value: 2}]
  },
])

const mitt = getCurrentInstance()

const check = true

mitt?.proxy?.$Bus.on('del', (id_list) => {
  del(id_list as number[])
})

async function del(id_list: number[]) {
  let rsp = await userDelAxios({id_list: id_list})
  if (rsp.code === 0) {
    Message.success(rsp.msg)
    mitt?.proxy?.$Bus.emit("refresh")
    return
  }
  Message.success(rsp.msg)
}


</script>

<template>
  <div>
    <user_add_modal></user_add_modal>

    <user_update_modal></user_update_modal>

    <blog_table :url="userListAxios"
                :optionTypeList="actionOptionList"
                :check="check"
                :filterOptionList="filterOptionList"
                :columns="columns"
                :limit="10"
                add="添加用户"
                update="编辑"
                del="删除">
    </blog_table>
  </div>
</template>

<style scoped>

</style>
